package com.atguigu.gmall.order.mapper;

import com.atguigu.gmall.model.order.OrderInfo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

/**
 * projectName: gmall
 *
 * @author: 陈鹏
 * time: 2022/10/10 19:24 星期一
 * description: 订单表的mapper映射
 */
@Mapper
public interface OrderInfoMapper extends BaseMapper<OrderInfo> {

    /**
     * 用户主动取消订单
     * @param finalStatus
     * @param orderId
     * @param preStatus
     * @param username
     * @return
     */
    @Update("update order_info set order_status = #{finalStatus}, " +
            "process_status = #{finalStatus} " +
            "where id = #{orderId} and " +
            "order_status = #{preStatus} and " +
            "user_id = #{username}")
    public int cancelOrder(@Param("finalStatus") String finalStatus,
                           @Param("orderId") Long orderId,
                           @Param("preStatus") String preStatus,
                           @Param("username") String username);

    /**
     * 超时取消订单
     * @param finalStatus
     * @param orderId
     * @param preStatus
     * @return
     */
    @Update("update order_info set order_status = #{finalStatus}," +
            "process_status = #{finalStatus} " +
            "where id = #{orderId} and " +
            "order_status = #{preStatus}")
    public int timeOutOrder(@Param("finalStatus") String finalStatus,
                           @Param("orderId") Long orderId,
                           @Param("preStatus") String preStatus);
}
